Skip to content

Adapt upstream enhancements: ACS 1-year hint (#145) + token flattening (#144)#2

Merged
brendanbabb merged 1 commit into
mainfrom
incorporate-upstream-145-144
Jun 1, 2026
Merged

Adapt upstream enhancements: ACS 1-year hint (#145) + token flattening (#144)#2
brendanbabb merged 1 commit into
mainfrom
incorporate-upstream-145-144

Conversation

@brendanbabb

Copy link
Copy Markdown

Incorporates two enhancements from upstream uscensusbureau/us-census-bureau-data-api-mcp, adapted to this fork's existing response-shape and error machinery rather than applied verbatim. Upstream's #145 is stacked on #144, so both arrive together.

uscensusbureau#145 — ACS 1-year population threshold (upstream PR)

ACS 1-year estimates only exist for areas of 65,000+ people; smaller areas return a bare 400 with no explanation — a common source of confusion for the model.

  • buildApiErrorMessage now detects acs/acs1 datasets and, on a 400, leads with the threshold explanation + an acs/acs5 suggestion before the generic discovery-tool guidance. Folded into our existing error helper instead of upstream's standalone inline branch.
  • Tool description gains a concise threshold note, consistent with our caveats-led description style.
  • Detector narrowed to acs/acs1 (upstream also matched bare acs1, which risks false positives).

uscensusbureau#144 — token management (upstream PR)

Upstream replaces pretty-printed JSON (JSON.stringify(data, null, 2)) with compact output to save ~30–40% of response tokens — relevant to our token-constrained 4o/Copilot consumer.

  • Our response-format.ts already replaced pretty-printed JSON in resolve-geography-fips and search-data-tables with numbered Record blocks, which exceeds feat: add content flattener for improved token management uscensusbureau/us-census-bureau-data-api-mcp#144's goal — left unchanged.
  • fetch-dataset-geography was the only tool still emitting indented JSON; switched to compact. Its payload (ParsedGeographyEntry[]) contains none of the fields upstream's flattener strips, so the standalone content-flattener.ts helper is intentionally not vendored (it would add a competing abstraction for zero extra benefit here).

Testing

  • tsc --noEmit clean.
  • 35 affected unit tests pass, including a new test for the ACS-1yr 400 path.
  • Integration tests require a Docker Postgres not available in this environment; the pure unit suites (mocked DB/fetch) were run in isolation.

🤖 Generated with Claude Code

…au#144 (token flattening)

Incorporates two upstream enhancements from uscensusbureau/us-census-bureau-data-api-mcp,
adapted to this fork's existing response-shape and error machinery rather than
applied verbatim.

uscensusbureau#145 -- ACS 1-year population threshold:
- buildApiErrorMessage now detects acs/acs1 datasets and, on a 400, leads with
  the 65,000-population-threshold explanation and an acs/acs5 suggestion before
  the generic discovery-tool guidance. Folded into our existing helper instead
  of upstream's standalone inline branch.
- Tool description gains a concise threshold note, consistent with our
  caveats-led description style.

uscensusbureau#144 -- token management:
- fetch-dataset-geography now emits compact JSON (drops the 2-space indent),
  the one tool still returning pretty-printed JSON. resolve-geography-fips and
  search-data-tables already exceed uscensusbureau#144's goal via response-format.ts, so the
  upstream content-flattener helper is intentionally not vendored.

Adds a unit test for the ACS-1yr 400 path. typecheck clean; affected unit
suites (35 tests) pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@brendanbabb brendanbabb merged commit 77a2b06 into main Jun 1, 2026
@brendanbabb brendanbabb deleted the incorporate-upstream-145-144 branch June 1, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant